#!/usr/bin/tcsh


umask 000
echo "umask 000"

@ i = 1
@ seed = 70
set bg = "&"
mkdir -p dataforR
rm -f dataforR/factor_matrix


foreach h ( `seq 1 5` )

mkdir -p holdout$h
cd holdout$h

echo "cd holdout$h"


mkdir -p data

rm -f -R trainpred
rm -f -R testpred
rm -f -R syn
rm -f -R eval


mkdir -p trainpred
mkdir -p testpred
mkdir -p syn
mkdir -p eval


foreach nseed ( `seq 1 10`)
	foreach setnum ( `ls -1 data/H*.train.*`)
		set setnum = $setnum:e
		foreach nh ( `echo 1 2 3 4 5`)
			
			# Do clumsy parallel. OBS: twice as many proccesses are made.
			if ( $i == "9") then
				set i = 1
				set bg = ''
			endif	
			
			set fn = ho${h}.dat${setnum}.nh${nh}.err2.sp.seed${seed}
			echo "nnbackprop -ec 150 -nc 5000 -nt 5 -nh $nh -s $seed -syn syn/syn_${fn}.dat -ol trainpred/trPred_${fn}.out -ot testpred/tePred_${fn}.out -tf data/H${h}.test_sp.${setnum} data/H${h}.train_sp.${setnum} &" 
			echo ${fn} ${h} ${setnum} ${nh} sp ${seed}	>> ../dataforR/factor_matrix
			@ seed++
			
			set fn = ho${h}.dat${setnum}.nh${nh}.err2.bl.seed${seed}
			echo "nnbackprop -ec 150 -nc 5000 -nt 5 -nh $nh -s $seed -syn syn/syn_${fn}.dat -ol trainpred/trPred_${fn}.out -ot testpred/tePred_${fn}.out -tf data/H${h}.test_bl.${setnum} data/H${h}.train_bl.${setnum} $bg"		
			echo ${fn} ${h} ${setnum} ${nh} bl ${seed} >> ../dataforR/factor_matrix

			set bg = "&"			
			@ i++
			@ seed++
			
		end
	end
end
cd ..
echo "cd .."
end
